package com.gsm.projects.jobDw;

import com.github.javafaker.Faker;

import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.util.Locale;

public class TestReadFile {


    public static void main(String[] args) throws Exception {

        // 数据库配置
        String url = "jdbc:mysql://localhost:3306/db_job_realtime_statistics?useSSL=false&serverTimezone=UTC&useUnicode=true&characterEncoding=UTF-8";
        String user = "root";
        String password = "123456";
        Connection conn = DriverManager.getConnection(url, user, password);

        Faker faker = new Faker(new Locale("zh_CN"));

        String sql = "INSERT INTO Employers (name, address, industry, contact_info) VALUES (?, ?, ?, ?)";
        PreparedStatement stmt = conn.prepareStatement(sql);

        BufferedReader br =
                new BufferedReader(new InputStreamReader(new FileInputStream("company.txt")));

        String  line = null;

        while((line = br.readLine()) != null)
        {
            String[] datas = line.split(":");

//            System.out.println(datas[0].trim());
//            System.out.println(datas[1].trim());

//            stmt.setString(1, faker.company().name()); // name
            stmt.setString(1 , datas[1].trim());
//            stmt.setString(2, faker.address().city()); // address
            stmt.setString(2, datas[2].trim()); // address
//            stmt.setString(3, faker.company().industry()); // industry
            stmt.setString(3, datas[0]); // industry

            stmt.setString(4, faker.internet().emailAddress()); // contact_info

            stmt.addBatch();
        }

        stmt.executeBatch();

        System.out.println("Data generation and insertion completed successfully.");


    }
}
